import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

import java.util.List;

import static java.lang.Thread.sleep;

public class Main {
    static WebDriver webDriver;
    public static void main(String[] args) throws InterruptedException {

        System.out.println(test("ArrayList"));

    }
    static String test(String s) throws InterruptedException {
        //启动chrome浏览器
        webDriver = new ChromeDriver();

        //打开百度
        webDriver.get("http://127.0.0.1:8080/index.html");

        //定位到输入框
        WebElement input = webDriver.findElement(By.id("search-input"));
        input.sendKeys(s);


        //定位搜索按钮
        WebElement button = webDriver.findElement(By.id("search-btn"));
        button.click();


        // 等待搜索结束
        sleep(1000);

        //获取搜索结果元素
        List<WebElement> elements = webDriver.findElements(By.className("item"));
        if (!elements.isEmpty()) {
            // 列表不为空，说明找到了元素
            return "true";
        }
        return "false";
    }
}
